#library "DragCorpsesScript"
#include "zcommon.acs"

bool dragging = false;
bool already_dragging = false;
// This is used to make certain things happen 
int counter = 0;

script "DragCorpsesScript" ENTER
{
	while(TRUE)
	{
		if (dragging == false)
		{ // fast skip if inactive
			Delay(1);
			continue;
		}
		int angle = GetActorAngle(0);
		int pitch = GetActorPitch(0);
		counter++;
		int actorMask = MF_CORPSE | MF_SPECIAL;
		int wallMask  = ML_BLOCKEVERYTHING | ML_BLOCKHITSCAN;
		int max_distance = 100.0;

		//NOTE:	PickActor requires careful handling. See the zdoom wiki about that!
		//		Actor's old TID needs to be saved, assigned a new TID, then restored back to old TID to keep things operational.
		int old_tid = PickActor(0, angle, pitch, max_distance, 0, actorMask, wallMask, PICKAF_RETURNTID);
		int new_tid = UniqueTID();

		if(PickActor(0, angle, pitch, max_distance, new_tid, actorMask, wallMask, PICKAF_FORCETID))
		{
			SetFont("BDCRA1");
			HudMessage("A");
			if (already_dragging == false)
			{
				already_dragging = true;
				SetActorProperty(0,APROP_SPEED,0.25);
				rollForSound(10);
			}
			if (counter % 50 == 0) 
			{ 
				rollForSound(20);
			}

			int radius = 75;
			int sn = sin(angle + 0.25);
			int cs = cos(angle + 0.25);

			int x = GetActorX(0) + sn * radius;
			int y = GetActorY(0) - cs * radius;
			int z = GetActorZ(new_tid);
			SetActorPosition(new_tid, x, y, z, 0);
		}
		else
		{
			dragging = false;
			already_dragging = false;
// 			SetActorProperty(0,APROP_SPEED,1.0);

		}

		Thing_ChangeTID(new_tid, old_tid);
		Delay(1);
	}

}

script "toggleDrag" (void)
{
	if (dragging == true)
	{
		dragging = false;
		already_dragging = false;

	}
	else
	{
		dragging = true;
		SetActorProperty(0,APROP_SPEED,1.0);
		PlaySound(0, "shesheavy");
		counter = 0;
	}
}


function void rollForSound(int chance)
{	
	str grunts[5] = {"grunt1", "grunt2", "grunt3", "grunt5"};
    int roller = Random (1, chance);
	if  (roller == 7)
	{
		PlaySound(0, "fartew");
		print(s:"A dry fart escapes the woman's body. She's gassy! She should have laid off the snacks");
	}
	else if (roller > 10){ 
		int gruntroller = Random (0, 3);
		PlaySound(0, grunts[gruntroller]);
	} else {	
	
		PlaySound(0, "unf");
	}
}